package com.easycarebn.main.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.easycarebn.main.model.ItemMeu;
import com.timbacsi.main.R;

public class MenuHomeAdapter extends BaseAdapter {
    ViewHolder holder;
    Context mContext;
    List<ItemMeu> arr;

    public MenuHomeAdapter(Context mContext, List<ItemMeu> arr) {
        this.mContext = mContext;
        this.arr = arr;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return arr.size();
    }

    @Override
    public ItemMeu getItem(int position) {
        return arr.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    public class ViewHolder {
        public TextView text;
        public TextView txtCountNew;
        public ImageView icon;
        private LinearLayout lineCount;

    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            // Utilities.log("convert null " + position);
            holder = new ViewHolder();
            convertView = View.inflate(mContext, R.layout.drawer_list_item, null);
            holder.text = (TextView) convertView.findViewById(R.id.title);
            holder.txtCountNew = (TextView) convertView.findViewById(R.id.lblCountNews);

            holder.icon = (ImageView) convertView.findViewById(R.id.icon);
            holder.lineCount = (LinearLayout) convertView.findViewById(R.id.lineCount);

            convertView.setTag(holder);
        } else {
            // Utilities.log("convert not null " + position);
            holder = (ViewHolder) convertView.getTag();
        }

        ItemMeu itemMeu = getItem(position);
        holder.text.setText(itemMeu.getTitle());
        holder.icon.setImageResource(itemMeu.getIcon());
        if (itemMeu.isNews()) {
            holder.lineCount.setVisibility(View.VISIBLE);
            holder.txtCountNew.setText(itemMeu.getCountNews() + "");
        } else {
            holder.lineCount.setVisibility(View.INVISIBLE);
        }

        return convertView;
    }

}
